<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>键盘事件</title>
</head>
<body>
    <input type="text" id="txt">
    <script>
        let txt = document.querySelector("#txt")
        txt.onkeydown = function(e){
            console.log(e);
            console.log('键盘按下');
        }
        txt.onkeypress = function(){
            console.log('产生输出字符');
        }
        txt.onkeyup = function(){
            console.log('键盘弹起');
        }
    </script>
</body>
</html>